﻿namespace AIC_Notification
{
    public class Error
    {
        public enum Owner { admin, ac, ec };

        public Owner ErrorOwner { get; set; }
        public string BoardName { get; set; }
        public string BoardUrl { get; set; }
        public string ListName { get; set; }
        public string CardName { get; set; }
        public string CardUrl { get; set; }
        public string ErrorMessage { get; set; }
        public AIC_Application Application { get; set; }

        public Error (Owner er, string em)
        {
            ErrorOwner = er;
            ErrorMessage = em;
            Global.SysUtil.Log(em, 2);
        }

        public Error(AIC_Application board, AIC_List list, AIC_Card card, Owner er, string em)
        {
            Application = board;
            BoardName = (board != null) ? board.BoardName : "";
            BoardUrl = (board != null) ? board.Url : "";
            ListName = (list != null) ? list.ListName : "";
            CardName = (card != null) ? card.CardName : "";
            CardUrl = (card != null) ? card.Url : "";
            ErrorOwner = er;
            ErrorMessage = em;

            string Context = "";

            if (BoardName != "")
                Context += BoardName;
            if (ListName != "")
                Context += ", " + ListName;
            if (CardName != "")
                Context += ", " + CardName;
            if (Context != "")
                em = em + "(" + Context + ")";

            Global.SysUtil.Log(em, 2);
        }
        /*
        public Error(Manatee.Trello.Board board, Manatee.Trello.List list, Manatee.Trello.Card card, Owner er, string em)
        {
            Application = null;
            BoardName = (board != null) ? board.Name : "";
            BoardUrl = (board != null) ? board.Url : "";
            ListName = (list != null) ? list.Name : "";
            CardName = (card != null) ? card.Name : "";
            CardUrl = (card != null) ? card.Url : "";
            ErrorOwner = er;
            ErrorMessage = em;

            string Context = "";

            if (BoardName != "")
                Context += BoardName;
            if (ListName != "")
                Context += ", " + ListName;
            if (CardName != "")
                Context += ", " + CardName;
            if (Context != "")
                em = em + "(" + Context + ")";

            Global.SysUtil.Log(em, 2);
        }
        */
    }
}
